using Logger7.Data;

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Logger7.Pages.Logger;

public class DetailsModel : PageModel
{
    private readonly SqlServerLoggerProcessor _Processor;
    public TLogger Item { get; set; } = default!;

    public DetailsModel(SqlServerLoggerProcessor processor)
    {
        _Processor = processor;
    }

    public async Task<IActionResult> OnGetAsync(long id)
    {
        var item = await _Processor.ReadAsync(id);
        if (item == null)
        {
            return NotFound();
        }
        else
        {
            Item = item;
            return Page();
        }
    }
    public async Task<IActionResult> OnPostAsync(long id)
    {
        await _Processor.DeleteAsync(id);
        return RedirectToPage("./Index");
    }
}
